package com.jeasonzhao.report.engine.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.PageContext;

import com.jeasonzhao.report.engine.ReportUserInfo;
import com.jeasonzhao.report.engine.irp.IUserProvider;

public abstract class AbstractHttpSessionUserProvider implements IUserProvider
{
    public AbstractHttpSessionUserProvider()
    {
        super();
    }

    protected HttpSession getSession(Object renderParameter)
    {
        HttpSession session = null;
        if(renderParameter instanceof PageContext)
        {
            session = ((PageContext) renderParameter).getSession();
        }
        else if(renderParameter instanceof HttpServletRequest)
        {
            session = ((HttpServletRequest) renderParameter).getSession();
        }
        return session;
    }

    public ReportUserInfo getCurrentUser(Object renderParameter)
    {
        return getSessionUser(renderParameter,this.getSession(renderParameter));
    }

    protected abstract ReportUserInfo getSessionUser(Object initParameter,HttpSession httpSession);
}
